package com.gqr.threadcoreknowledge.sixstates;

/**
 * Copyright (C), 2020-2024,gqr
 * FileName:NewRunnableTerminated
 * author:guqingrong
 * Date:2024-04-18 22:21
 * Description:展示线程的NEW RUNNABLE TERMINATED三种状态
 * 即使是正在运行,也是runnable状态 而不是runnable
 * History:
 * <author>    <time>    <version>    <desc>
 * 作者姓名     修改时间     版本号        描述
 */
public class NewRunnableTerminated implements Runnable{

    public static void main(String[] args) {
        Thread thread = new Thread(new NewRunnableTerminated());
        // 打印出NEW的状态
        System.out.println(thread.getState());
        thread.start();
        // 打印出RUNNABLE的状态
        System.out.println(thread.getState());
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 打印出RUNNABLE的状态 即使是正在运行 也是RUNNABLE
        System.out.println(thread.getState());
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 打印出TERMINATED的状态 即使是正在运行 也是TERMINATED
        System.out.println(thread.getState());
    }
    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println(i);
        }
    }
}
